package websocket

import (
	order "gateway/basic/proto/orderproto"
)

// Notifier 通知器接口，避免循环依赖
type Notifier interface {
	NotifyOrderCreated(orderInfo *order.OrderInfo)
	NotifyOrderUpdate(orderInfo *order.OrderInfo)
	NotifyOrderStatusChange(orderInfo *order.OrderInfo, oldStatus int32)
	NotifyPaymentUpdate(orderInfo *order.OrderInfo)
}

// 全局通知器实例
var globalNotifier Notifier

// SetNotifier 设置全局通知器
func SetNotifier(notifier Notifier) {
	globalNotifier = notifier
}

// GetNotifier 获取全局通知器
func GetNotifier() Notifier {
	return globalNotifier
}

// NotifyOrderCreatedGlobal 全局订单创建通知
func NotifyOrderCreatedGlobal(orderInfo *order.OrderInfo) {
	if globalNotifier != nil {
		globalNotifier.NotifyOrderCreated(orderInfo)
	}
}

// NotifyOrderUpdateGlobal 全局订单更新通知
func NotifyOrderUpdateGlobal(orderInfo *order.OrderInfo) {
	if globalNotifier != nil {
		globalNotifier.NotifyOrderUpdate(orderInfo)
	}
}

// NotifyOrderStatusChangeGlobal 全局订单状态变更通知
func NotifyOrderStatusChangeGlobal(orderInfo *order.OrderInfo, oldStatus int32) {
	if globalNotifier != nil {
		globalNotifier.NotifyOrderStatusChange(orderInfo, oldStatus)
	}
}

// NotifyPaymentUpdateGlobal 全局支付更新通知
func NotifyPaymentUpdateGlobal(orderInfo *order.OrderInfo) {
	if globalNotifier != nil {
		globalNotifier.NotifyPaymentUpdate(orderInfo)
	}
}

// NotifyOrderAssigned 通知订单分配
func NotifyOrderAssigned(assignedTo string, orderID uint64) {
	if globalNotifier != nil {
		// 这里可以实现订单分配通知逻辑
		// 例如发送给指定操作员
	}
}